package com.zsjt.kmp;

/**
 * @author ZhanBo
 * @date 2020/5/31
 */
public class BruteForceMatch {

    public static void main(String[] args) {
        String s1 ="abcdefdf";
        String s2 ="df";
        System.out.println(bruteMatch(s1, s2));
    }

    /**
     *
     * @param str1  母串
     * @param str2  子串
     * @return
     */
    public static int bruteMatch(String str1 ,String str2){
        char[] ch1 = str1.toCharArray();
        char[] ch2 = str2.toCharArray();
        int ch1l = ch1.length;
        int ch2l = ch2.length;
        int i = 0;
        int j = 0;
        while (i< ch1l && j <ch2l){
            if (ch1[i] == ch2[j]){
                i++;
                j++;
            }else {
                i = i -(j-1);
                j = 0;
            }
        }
        if (j == ch2l){
            return i-j;
        }else {
            return -1;
        }
    }
}
